<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
	<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
	<meta HTTP-EQUIV="Expires" CONTENT="0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试结果统计</title>
<style type="text/css">
	@import "../dojo-release-1.5.0/dijit/themes/tundra/tundra.css";
	@import "../dojo-release-1.5.0/dojo/resources/dojo.css";
	@import "../dojo-release-1.5.0/dojox/grid/resources/tundraGrid.css";
</style>
<script type="text/javascript" src="../dojo-release-1.5.0/dojo/dojo.js" djConfig="parseOnLoad:true"></script>
<script type="text/javascript" src="../framework/uiutil.js"></script>
<script type="text/javascript">
dojo.addOnLoad(function(){
	initProductSelect();
	dojo.connect(dojo.byId("productSelect"),"onblur",initSuiteSelect);
});

//初始化产品选择列表
function initProductSelect(){
	dojo.xhrGet({
		 url:"../bkgrd/getProductList.do",
		 handleAs:"json",
		 load:function(response){
			 ps = [];
			 for(var i in response){
				 ps.push({value:response[i],name:response[i]});
			 }
			 D.initCombo("productSelect",ps)
		 }
	});
}


//初始化测试项
function initSuiteSelect(){
	var productName = D.getComboValue("productSelect");
	dojo.xhrPost({
		 url:"../bkgrd/getSuiteList.do",
		 content:{productName:productName},
		 handleAs:"json",
		 load:function(response){
			 ps = [];
			 for(var i in response){
				 ps.push({value:response[i],name:response[i]});
			 }
			 D.initCombo("suiteSelect",ps)
		 }
	});
}

function query(){
	if(!dijit.byId("productSelect").isValid() ||
		!dijit.byId("startDate").isValid() ||
		!dijit.byId("endDate").isValid()){
		alert("请选择产品类型和检测时间范围");
		return;
	}
	var productName = D.getComboValue("productSelect");
	var suiteName =  D.getComboValue("suiteSelect");
	var startDate = D.getWholeDateTime('startDate',null);
	var endDate = D.getWholeDateTime('endDate',null);
	
	
	dojo.xhrPost({
		 url:"../bkgrd/queryWorkbayStatistic.do",
		 encoding : 'UTF-8',
		 content:{
			 productName:productName,
			 suiteName:suiteName,
			 startDate:startDate.getTime(),
			 endDate:endDate.getTime()
		 },
		 preventCache:true,	 
		 handleAs:"json",
		 load:function(response){
			if(response == ""){
				alert("没有结果，请检查查询条件。");
				return;
			}
			displayResult(response);
		 }
	});
}

function displayResult(resultList){
	var allSucc = 0;
	var allFail = 0;

	for(var i in resultList){
		var item = resultList[i];
		allSucc += parseInt(item["success"]);
		allFail += parseInt(item["fail"]);
		item["succRate"] = (parseInt(item["success"])*100 / (parseInt(item["success"])+parseInt(item["fail"]))).toFixed(2)+" %";
	}

	D.fillTableData("grid",resultList);
	dojo.byId('overallStatisticResult').innerHTML = "<table width=90% border=1><tr><td>总成功数:</td><td>"+
		allSucc+"</td><td>总失败数:</td><td>"+allFail+"</td></tr><tr><td>总测试数:</td><td>"+
		(allSucc+allFail)+"</td><td>成功率</td><td>"+(allSucc*100/(allSucc+allFail)).toFixed(2)+"%</td></tr></table>";
}

</script>

<style type="text/css">
#testSuiteTable{
	border:1px solid #333;
	width:100%;
	margin:10px;
	height:500px;
	font-size:0.9em;
}
</style>
</head>
<body class="tundra">

<table width="100%">
<tr><td>请选择产品类型：</td><td><select dojoType="dijit.form.FilteringSelect" id="productSelect" value=""></select></td>
<td>测试项</td><td>
<select dojoType="dijit.form.FilteringSelect" id="suiteSelect" value="" required="false"></select>
</td></tr>
<tr><td>测试时间：</td><td colspan="3">
<input type="text" id="startDate"  dojoType="dijit.form.DateTextBox" required="true" onchange="endDate.focus()"/>&nbsp;至&nbsp;
<input type="text" id="endDate" dojoType="dijit.form.DateTextBox" required="true"/>
</td></tr>
<tr><td colspan="2" align="center">
<button dojoType="dijit.form.Button" id="query" onclick="query(0,-1);">查询统计结果</button>
</td></tr>
</table>
<div>
<table dojoType="dojox.grid.DataGrid" id="grid"  autoWidth="true">
 <thead>
	<tr>
	     <th field="workbay" width="150px">工位编号</th>
	     <th field="suiteName" width="120px">测试项</th>
	     <th field="success" width="120px">成功数量</th>
	     <th field="fail" width="120px">失败数量</th>
	     <th field="succRate" width="120px">成功率</th>
	</tr>
</thead>
</table>
</div>

<h2>整体统计结果</h2>
<div id="overallStatisticResult">


</div>
</body>
</html>